import { http } from "@/utils/http";
import { type BaseResponseType, baseUrlApi } from "@/api/types";


/** 订单详情 */
export interface OrderDetail {
    /** cas号 */
    casNo: string;
    /** 目录价 */
    fbidprice: number | number;
    /** 品牌 */
    fbrand: string;
    /** 货号 */
    fgoodcode: string;
    /** 商品名 */
    fgoodname: string;
    /** 商品id */
    fgoodsId: number;
    /** 最终售价 */
    fprice: number | number;
    /** 数量 */
    fquantity: number;
    /** 规格 */
    fspec: string;
    /** 计量单位 */
    funit: string;
}

/** 订单列表 */
export interface OrderList {
    /** 购买人 */
    buyername: string;
    /** 联系方式 */
    contactphone: string;
    fbuyertelephone: string;
    /** 订单时间 */
    orderdate: string;
    /** 订单编号 */
    orderno: string;
    /** 采购单位 */
    orgname: string;
    receivedpayment: string;
    /** 订单总价 */
    totalprice: string;
    productinfo: Array<OrderDetail>;
    /** 订单状态 */
    logisticsstatus: string;
}

/** 查询订单响应信息 */
export interface OrderListResponse extends BaseResponseType {
    data: {
        orderlist: Array<OrderList>;
        total: number;
    };
}
/** 临时订单列表类型 */
export interface TempOrderList extends BaseResponseType {
    data: {
        data: Array<OrderList>;
        /** 商品总页数 */
        total: number;
    };
}

/** 订单列表搜索 */
export interface SearchOrderList {
    /** 当前页码 */
    page: number;
    /** 每页数量 */
    size: number;
}

/** 订单详情搜索 */
export interface SearchOrderDetail {
    /** 订单编号 */
    orderno: string;
}

/** 物流信息节点 */
export interface LogisticsStatusNode {
    /** 描述信息 */
    context: string;
    /** 签收时间 */
    time: string;
    ftime: string;
    /** 物流状态 */
    status: string;
    /** 状态编码 */
    statuscode: string;
    /** 地区编码 */
    areacode: string;
    /** 地区名称 */
    areaname: string;
    areacenter: string;
    location: string;
    areapinyin: string;
}

/** 物流信息列表 */
export interface LogisticsInfo extends BaseResponseType {
    data: {
        Logisticsinfo: {
            com: string;
            number: string;
            data: Array<LogisticsStatusNode>;
            state: string;
        };
    };
}

/** 获取订单列表 */
export let getOrderList = (pageNum = 1) => {
    return http.get<OrderListResponse, SearchOrderList>(
        baseUrlApi("/order/getorder"),
        {
            params: { page: pageNum, size: 10 },
        }
    );
};

/** 获取订单详情 */
export let getOrderDeatail = (orderId) => {
    return http.get<OrderListResponse, SearchOrderDetail>(
        baseUrlApi("/order/getorderdetail"),
        { params: { orderno: orderId } }
    );
};


/** 获取指定订单ID的订单信息 */
export let getOderById = (orderId: string) => {
    return http.get<any, any>(baseUrlApi("/order/getorder"), {
        params: { orderno: orderId },
    });
};

/** 获取指定商品ID的物流信息 */
export let getOrderLogisticsById = (orderId: string, goodsid: string) => {
    return http.get<LogisticsInfo, any>(
        baseUrlApi(`/order/logistics/query/${orderId}/${goodsid}`)
    );
};
